package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.phonehelp.MobileCreditScore;
import com.ucredit.babel.common.model.third.phonehelp.MobileCreditScoreData;
import com.ucredit.babel.common.model.third.phonehelp.MobileCreditScoreY01Record;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 电话邦邦信分
 *
 * @author renzhanzheng
 */

public class MobileCreditScoreY01Parse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 电话邦邦信分
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        MobileCreditScoreY01Record obj = (MobileCreditScoreY01Record)model;
        MobileCreditScoreData data = obj.getData() == null ? new MobileCreditScoreData() : obj.getData() ;
        MobileCreditScore dataScore = data.getData() == null ? new MobileCreditScore() : data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        //接口状态码
        sb.append(data.getStatus() == null ? "" : data.getStatus()).append(CRT001);
        //主接口描述
        sb.append(data.getMsg() == null ? "" : data.getMsg()).append(CRT001);
        //本次成功请求的唯一标识
        sb.append(dataScore.getSid() == null ? "" : dataScore.getSid()).append(CRT001);
        //本次输出结果对应的有效日期
        sb.append(dataScore.getResultDate() == null ? "" : dataScore.getResultDate()).append(CRT001);
        //邦信分_评分 Y01，0~900
        sb.append(dataScore.getScore() == null ? "" : dataScore.getScore()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n","").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_dianhuabang_bxfscore_inc";
    }

    @Override
    public String getType() {
        return RecordType.MOBILE_CREDITSCORE_Y01_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "电话邦邦信分";
    }
}
